<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link href='/css/styles.css' rel='stylesheet' type='text/css' />
    <link href='/images/favicon.png' rel='shortcut icon' />
    <script src='/js/jquery.min.1.4.js'></script>
    <script src='/js/app.js'></script>
    <script src='/js/common.js'></script>
    
    <meta content='width=device-width, minimum-scale=1.0, maximum-scale=1.0' name='viewport' />
    <title>redis - 命令</title>
	<meta http-equiv="description" content="redis中文资料站，下载安装redis，查找redis常用命令（commands），选择适合的redis客户端方式，配置redis主从（master-slave），阅读redis官方文档，社区里了解更多redis信息，提交redis的bug。" />
	
  </head>
  <body class=''>
    <script src='/js/head.js'></script>
    <div class='text'>
      <h1 class='command'>
        <span id='command_name_span' class='name'></span>
        <span id='command_args_span' class='arg'></span>
      </h1>
      <article>
      	<aside>
        	<script type='text/javascript'>showCmdURL();</script>
        </aside>
        
        <div class='metadata'>
          <p><strong>加入版本 <span id='command_ver_span'></span>。</strong></p>
          <p><strong>时间复杂度：</strong> O(1)。</p>
        </div>
        
        <p>Atomically returns and removes the last element (tail) of the list stored at
        <code>source</code>, and pushes the element at the first element (head) of the list stored
        at <code>destination</code>.</p>
        
        <p>For example: consider <code>source</code> holding the list <code>a,b,c</code>, and <code>destination</code>
        holding the list <code>x,y,z</code>.
        Executing <a href="/commands/rpoplpush.html">RPOPLPUSH</a> results in <code>source</code> holding <code>a,b</code> and <code>destination</code>
        holding <code>c,x,y,z</code>.</p>
        
        <p>If <code>source</code> does not exist, the value <code>nil</code> is returned and no operation is
        performed.
        If <code>source</code> and <code>destination</code> are the same, the operation is equivalent to
        removing the last element from the list and pushing it as first element of the
        list, so it can be considered as a list rotation command.</p>
        
        <h2>Return value</h2>
        
        <p><a href="/topics/protocol.html#bulk-reply">Bulk reply</a>: the element being popped and pushed.</p>
        
        <h2>Examples</h2>
        
        <div class='example' data-session='e5571c96bffba603e58538bfc6b20ad7'>
          <span class='monospace prompt'>redis&gt;&nbsp;</span>
          <span class='monospace command'>RPUSH mylist &quot;one&quot;</span>
          <pre>(integer) 1</pre>
          <span class='monospace prompt'>redis&gt;&nbsp;</span>
          <span class='monospace command'>RPUSH mylist &quot;two&quot;</span>
          <pre>(integer) 2</pre>
          <span class='monospace prompt'>redis&gt;&nbsp;</span>
          <span class='monospace command'>RPUSH mylist &quot;three&quot;</span>
          <pre>(integer) 3</pre>
          <span class='monospace prompt'>redis&gt;&nbsp;</span>
          <span class='monospace command'>RPOPLPUSH mylist myotherlist</span>
          <pre>"three"</pre>
          <span class='monospace prompt'>redis&gt;&nbsp;</span>
          <span class='monospace command'>LRANGE mylist 0 -1</span>
          <pre>1) "one"&#x000A;2) "two"</pre>
          <span class='monospace prompt'>redis&gt;&nbsp;</span>
          <span class='monospace command'>LRANGE myotherlist 0 -1</span>
          <pre>1) "three"</pre><form>
            <span class='monospace prompt'>redis&gt;&nbsp;</span>
            <input autocomplete='off' name='command' spellcheck='false' type='text' />
          </form></div>
        
        
        <h2>Pattern: Reliable queue</h2>
        
        <p>Redis is often used as a messaging server to implement processing of background
        jobs or other kinds of messaging tasks.
        A simple form of queue is often obtained pushing values into a list in the
        producer side, and waiting for this values in the consumer side using <a href="/commands/rpop.html">RPOP</a>
        (using polling), or <a href="/commands/brpop.html">BRPOP</a> if the client is better served by a blocking
        operation.</p>
        
        <p>However in this context the obtained queue is not <em>reliable</em> as messages can
        be lost, for example in the case there is a network problem or if the consumer
        crashes just after the message is received but it is still to process.</p>
        
        <p><a href="/commands/rpoplpush.html">RPOPLPUSH</a> (or <a href="/commands/brpoplpush.html">BRPOPLPUSH</a> for the blocking variant) offers a way to avoid
        this problem: the consumer fetches the message and at the same time pushes it
        into a <em>processing</em> list.
        It will use the <a href="/commands/lrem.html">LREM</a> command in order to remove the message from the
        <em>processing</em> list once the message has been processed.</p>
        
        <p>An additional client may monitor the <em>processing</em> list for items that remain
        there for too much time, and will push those timed out items into the queue
        again if needed.</p>
        
        <h2>Pattern: Circular list</h2>

        
        <p>Using <a href="/commands/rpoplpush.html">RPOPLPUSH</a> with the same source and destination key, a client can visit
        all the elements of an N-elements list, one after the other, in <span class="math">O(N) </span>without
        transferring the full list from the server to the client using a single <a href="/commands/lrange.html">LRANGE</a>
        operation.</p>
        
        <p>The above pattern works even if the following two conditions: * There are
        multiple clients rotating the list: they&#39;ll fetch different elements, until all
        the elements of the list are visited, and the process restarts.
        * Even if other clients are actively pushing new items at the end of the list.</p>
        
        <p>The above makes it very simple to implement a system where a set of items must
        be processed by N workers continuously as fast as possible.
        An example is a monitoring system that must check that a set of web sites are
        reachable, with the smallest delay possible, using a number of parallel workers.</p>
        
        <p>Note that this implementation of workers is trivially scalable and reliable,
        because even if a message is lost the item is still in the queue and will be
        processed at the next iteration.</p>
        
      </article>
    </div>
    <script type='text/javascript'>startShow();</script>
    <div class='text' id='comments'>
      <div id='disqus_thread'></div>
      <script type='text/javascript'>
        //<![CDATA[
          var disqus_shortname = 'rediscn';
          
          // The following are highly recommended additional parameters. Remove the slashes in front to use.
          var disqus_identifier = 'command_'+curCommandObj.key;
          var disqus_url = curCommandObj.getdisqusUrl();
          
          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
        //]]>
      </script>
      <a class='dsq-brlink' href='http://disqus.com'>
        Comments powered by
        <span class='logo-disqus'>
          Disqus
        </span>
      </a>
    </div>

    
    <script src='/js/foot.js'></script>
    
  </body>
</html>
